<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
{{include file="layouts/_head"}}
<link rel="stylesheet" type="text/css" href="/static/admin/style/product.css" />
</head>
<body>
<div class="main">
    <ol class="breadcrumb">
        <li><i class="icon_home iconfont"></i>首页</li>
        <li>产品管理</li>
        <li><a href="javascript:history.go(-1);">产品列表</a></li>
        <li class="active">编辑产品</li>
    </ol>
    <div class="main-head-info error-info bg-danger"></div>
    <div class="main-con">
        <ul class="nav nav-tabs" id="tabs">
            <li class="active"><a href="javascript:void(0)" data-id="#a">基础信息</a></li>
            <li><a href="javascript:void(0)" data-id="#b">销售信息</a></li>
            <li><a href="javascript:void(0)" data-id="#c">图文描述</a></li>
        </ul>
        <form class="form-horizontal margin-t-30" action="{{:url('/admin/product/update')}}" method="post" id="form" autocomplete="off">
            <input type="hidden" name="id" value="{{$product.id}}">
            <!-- 基础信息 start -->
            <div id="a" class="tab-box">
                <div class="form-group">
                    <span class="col-sm-2 control-label">当前分类：</span>
                    <div class="col-sm-8">
                        <p class="form-control-static">{{$product.full_category_name}}</p>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label"><span class="color-red">*</span> 产品名：</span>
                    <div class="col-sm-4 input-group">
                        <input class="form-control" name="name" value="{{$product.name}}">
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label"><span class="color-red">*</span> 分类：</span>
                    <div class="col-sm-2 input-group">
                        <select class="form-control" name="category_id">
                            {{volist name="categorys" key="key" id="vo"}}
                            {{if $product.category_id == $vo.id}}
                            <option selected="true" value="{{$vo.id}}">{{php}}for($i = 1; $i < $vo['level']; $i++) {echo '&nbsp;&nbsp;&nbsp;&nbsp;';}{{/php}}{{$vo.name}}</option>
                            {{else}}
                            <option value="{{$vo.id}}">{{php}}for($i = 1; $i < $vo['level']; $i++) {echo '&nbsp;&nbsp;&nbsp;&nbsp;';}{{/php}}{{$vo.name}}</option>
                            {{/if}}
                            {{/volist}}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">品牌：</span>
                    <div class="col-sm-2 input-group">
                        <select class="form-control" name="brand_id">
                            <option value="">请选择</option>
                            {{volist name="brands" id="vo"}}
                            <option value="{{$vo.id}}" {{if $vo.id == $product.brand_id}} selected {{/if}}>{{$vo.name}}</option>
                            {{/volist}}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label"><span class="color-red">*</span> 包邮：</span>
                    <div class="col-sm-8 input-group">
                        <select class="form-control width-100" name="freight">
                            <option {{if $product.freight.freight == 1}} selected="true" {{/if}} value="1">是</option>
                            <option {{if $product.freight.freight == 2}} selected="true" {{/if}} value="2">否</option>
                        </select>
                        <div class="select-freight {{if $product.freight.freight != 2}}none{{/if}}">
                            {{if $freights}}
                            <select class="form-control" name="freight_id">
                                <option value="">选择运费模板</option>
                                {{volist name="$freights" id="vo"}}
                                <option {{if $product.freight.freight_id == $vo.id}} selected="true" {{/if}} value="{{$vo.id}}">{{$vo.name}}</option>
                                {{/volist}}
                            </select>
                            {{else}}
                            <p class="form-control-static"><a href="/admin/shipping_freight.html">请先添加运费模板</a></p>
                            {{/if}}
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">重量：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" name="weight" value="{{$product.freight.weight}}"><span class="input-group-addon">克</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">体积：</span>
                    <div class="col-sm-2 input-group">
                      <input class="form-control" name="volume" value="{{$product.freight.volume}}"><span class="input-group-addon">立方米</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">排序：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" name="sort" value="{{$product.sort}}">
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">状态：</span>
                    <div class="col-sm-2 input-group">
                        <select class="form-control" name="status">
                            <option value="1" {{if $product.status == 1}}selected="true"{{/if}}>上架</option>
                            <option value="0" {{if $product.status == 0}}selected="true"{{/if}}>下架</option>
                        </select>
                    </div>
                </div>
            </div>
            <!-- 基础信息 end -->
            <!-- 销售信息 start -->
            <div id="b" class="tab-box">
                <div class="form-group">
                    <span class="col-sm-2 control-label"><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="不同产品模型对应不同销售规格和产品属性"></i> 模型：</span>
                    <div class="col-sm-2 input-group">
                        <select class="form-control" name="product_model_id">
                            <option value="">请选择产品模型</option>
                            {{volist name="$product_models" id="vo"}}
                            <option value="{{$vo.id}}" {{if $product.model_id == $vo.id}} selected {{/if}}>{{$vo.name}}</option>
                            {{/volist}}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label"><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="商家编码不允许被修改"></i> 商家编码：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" disabled="true" value="{{$product.default_sku.sku}}">
                        <input type="hidden" name="sku" value="{{$product.default_sku.sku}}">
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label"><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="最终销售价格"></i> <span class="color-red">*</span> 销售价：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" name="sale_price" value="{{$product.default_sku.sale_price}}">
                        <span class="input-group-addon">元</span>
                    </div>
                </div>
                <div class="form-group">
                    <span class="col-sm-2 control-label">库存：</span>
                    <div class="col-sm-2 input-group">
                        <input class="form-control" name="stock" value="{{$product.default_sku.stock}}">
                    </div>
                </div>
                <div id="product_gs" {{if empty($product.model_id)}} class="none" {{/if}}>
                    <hr/>
                    <div class="form-group"><span class="col-sm-2 control-label"><strong>销售规格</strong></span></div>
                    <div class="form-group" id="product_specifications">
                        <div class="form-group specification">
                            <span class="col-sm-2 control-label">销售规格：</span>
                            <div class="col-sm-4 form-control-static specification_box">
                                {{if !empty($product.model.product_specifications)}}
                                {{volist name="$product.model.product_specifications" id="vo"}}
                                <div class="items" data-id="{{$vo.id}}" data-name="{{$vo.name}}">
                                    <p class="specification_title">{{$vo.name}}</p>
                                    {{volist name="$vo.options" id="vo_option"}}
                                    <label class="radio-inline iconfont"><input class="none" onclick="radioCancelSelected(this)" type="radio" name="specification_{{$vo.id}}" data-id="{{$vo_option.id}}" data-value="{{$vo_option.value}}">{{$vo_option.value}}</label>
                                    {{/volist}}
                                </div>
                                {{/volist}}
                                {{/if}}
                                <a class="btn btn-primary btn-sm" onclick="combinationSpecification();">生成组合</a>
                            </div>
                        </div>
                        <div class="form-group specification {{if empty($product.skus)}}none{{/if}}" id="specification_group">
                            <span class="col-sm-2 control-label">销售规格组：</span>
                            <div class="col-sm-6 form-control-static">
                                <div class="row">
                                    <table class="table table-bordered">
                                        <tbody id="skus">
                                            {{if !empty($product.skus)}}
                                            <tr class="th">
                                                {{volist name="$product['skus'][0]['specifications']" id="vo"}}
                                                <td class="dynamic_add" data-id="{{$vo.product_specification_id}}">{{$vo.product_specification_name}}</td>
                                                {{/volist}}
                                                <td>销售价</td>
                                                <td>库存</td>
                                                <td>排序</td>
                                                <td><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="已生成的商家编码不允许被修改"></i> 商家编码</td>
                                                <td>操作</td>
                                                <td><a class="btn btn-primary btn-xs" onclick="fillData();">填充</a> <i class="iconfont iconfont-question"
                                                        data-toggle="tooltip" data-placement="top" data-original-title="将填充上方产品基础数据中的销售价和库存"></i></td>
                                            </tr>
                                            {{volist name="$product.skus" id="vo"}}
                                            <tr class="tr" data-id="{{$vo.option_id_connect}}" data-name="{{$vo.option_value_connect}}">
                                                {{volist name="$vo.specifications" id="vo_option"}}
                                                <td>{{$vo_option.product_specification_option_value}}</td>
                                                {{/volist}}
                                                <td><span class="color-red">*</span> <input type="text" name="specification_option_id[{{$vo.option_id_connect}}][sale_price]" class="width-80" value="{{$vo.sale_price}}"></td>
                                                <td><input type="text" name="specification_option_id[{{$vo.option_id_connect}}][stock]" class="width-50" value="{{$vo.stock}}"></td>
                                                <td><input type="text" name="specification_option_id[{{$vo.option_id_connect}}][sort]" class="width-50" value="{{$vo.sort}}"></td>
                                                <td><input type="text" class="width-110"  disabled="true" value="{{$vo.sku}}"><input type="hidden" name="specification_option_id[{{$vo.option_id_connect}}][sku]" value="{{$vo.sku}}">
                                                    <input type="hidden" name="specification_option_id[{{$vo.option_id_connect}}][sku_id]" value="{{$vo.id}}"></td>
                                                <td><a class="btn btn-danger btn-xs" onclick="removeSpecification(this);">移除</a></td>
                                            </tr>
                                            {{/volist}}
                                            {{/if}}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr/>
                    <div class="form-group"><span class="col-sm-2 control-label"><strong>产品属性</strong></span></div>
                    <div class="form-group" id="product_attributes">
                        {{if !empty($product.model.product_attributes)}}
                        {{volist name="$product.model.product_attributes" id="vo"}}
                        <div class="form-group">
                            <span class="col-sm-2 control-label">{{$vo.name}}</span>
                            <div class="col-sm-2 input-group">
                                {{if $vo.type == 'select'}}
                                <select class="form-control" name="attributes[{{$vo.id}}]">
                                    <option value="">请选择</option>
                                    {{volist name="$vo.options" id="vo_option"}}
                                    <option {{if $vo_option.value == $vo.value}} selected {{/if}} value="{{$vo_option.value}}">{{$vo_option.value}}</option>
                                    {{/volist}}
                                </select>    
                                {{else}}
                                <input class="form-control" name="attributes[{{$vo.id}}]" value="{{$vo.value}}">
                                {{/if}}
                            </div>
                        </div>        
                        {{/volist}}
                        {{else}}
                        <span class="col-sm-2"></span><span class="col-sm-6 help-block">该产品模型中暂无产品属性选项！</span>
                        {{/if}}
                    </div>
                </div>
            </div>
            <!-- 销售信息 end -->
            <!-- 产品图片 start -->
            <div id="c" class="tab-box">
                <div class="form-group" id="product_image">
                    <span class="col-sm-2 control-label">产品图片：</span>
                    <div class="col-sm-10 input-group">
                        <div class="product_images">
                            {{php}} $count = 6; {{/php}}
                            {{if empty($product.default_sku.images) || $product['default_sku']['images'][0]['default'] != 1}}
                            {{php}} $count = 5; {{/php}}
                            <div class="product_image fmr wh-80x80 fmr_current_ident" data-name="image[999]"></div>
                            {{/if}}
                            {{volist name="$product.default_sku.images" id="vo"}}
                            <div class="product_image {{if $vo.default != 1}}sld{{/if}} fmr wh-80x80 uploaded" data-name="image[already_{{$vo.id}}]">
                                <input name="image[already_{{$vo.id}}]" type="hidden" value="{{$vo.image}}">
                                <img src="{{$vo.image}}">
                                <i class="iconfont fmr_remove"></i>
                            </div>
                            {{/volist}}
                            {{for start="0" end="($count - count($product['default_sku']['images']))"}}
                            <div class="product_image sld fmr wh-80x80" data-name="image[]"></div>
                            {{/for}}
                        </div>
                    </div>
                </div>
                <!-- sku 图片处理 start -->
                <div id="sku_image">
                    <div class="form-group {{if empty($product.skus)}} none {{/if}}" id="sku_image_switch">
                        <p class="col-sm-2 control-label"><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="若未配置，默认使用主图"></i> <a class="btn btn-info btn-xs" onclick="setSkuImage();">配置规格图</a></p>
                    </div>
                    <div {{if empty($product.skus)}} class="none" {{/if}} id="sku_image_items">
                        {{volist name="product.skus" id="vo"}}
                        {{if !empty($vo.images)}}
                        <div class="form-group specification_option_id_{{$vo.option_id_connect}}">
                            <span class="col-sm-2 control-label">{{$vo.option_value_connect}}：</span>
                            <div class="col-sm-10 input-group">
                                <div class="product_images">
                                    {{php}} $count = 6; {{/php}}
                                    {{if empty($vo.images) || $vo['images'][0]['default'] != 1}}
                                    {{php}} $count = 5; {{/php}}
                                    <div class="product_image fmr wh-80x80" data-name="images[{{$vo.option_id_connect}}][999]"></div>
                                    {{/if}}
                                    {{volist name="$vo.images" id="vo_image"}}
                                    <div class="product_image sld fmr wh-80x80 uploaded" data-name="images[{{$vo.option_id_connect}}][already_{{$vo_image.id}}]">
                                        <input name="images[{{$vo.option_id_connect}}][already_{{$vo_image.id}}]" type="hidden" value="{{$vo_image.image}}">
                                        <img src="{{$vo_image.image}}">
                                        <i class="iconfont fmr_remove"></i>
                                    </div>
                                    {{/volist}}
                                    {{for start="0" end="($count - count($vo['images']))"}}
                                    <div class="product_image sld fmr wh-80x80" data-name="images[{{$vo.option_id_connect}}][]"></div>
                                    {{/for}}
                                    <a class="btn btn-primary btn-xs margin-t-30" onclick="useProductImage(this);">使用商品图片</a>
                                </div>
                            </div>
                        </div>
                        {{/if}}
                        {{/volist}}
                    </div>
                </div>
                <!-- sku 图片处理 end -->
                <div class="form-group">
                    <span class="col-sm-2 control-label">产品详情：</span>
                    <div class="col-sm-8 input-group">
                        <textarea class="summernote" name="content">{{$product.content}}</textarea>
                    </div>
                </div>
            </div>    
            <!-- 产品图片 end -->    
            <div class="foot_btn_blank"></div>
            <div class="foot_btn">
                <div class="box">
                    <button type="submit" class="btn btn-primary">提交产品信息</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="/static/admin/plugins/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript" src="/static/admin/plugins/Bootstrap/3.3.7/js/bootstrap.js"></script>
<script type="text/javascript" src="/static/admin/script/common.js"></script>
<script type="text/javascript" src="/static/admin/plugins/layer/2.4/layer.js"></script>
{{include file="shared/_jquery_validation"}}
{{include file="shared/_summernote"}}
<script type="text/javascript" src="/static/admin/script/product.js"></script>
<script type="text/javascript">
$("#form").validate({
    rules: {
        name: { required: true },
        sale_price: { required: true },
        category_id: { required: true },
    },
    messages: {
        name: '产品名不能为空',
        sale_price: '产品销售价不能为空',
        category_id: '产品分类不能为空',
    },
    submitHandler: function () {
        layer.confirm('确认提交？', function() {
            layer.closeAll();
            var load = layer.load();
            $("#form").ajaxSubmit(function(data) {
                layer.close(load);
                if (data.code == 401) {
                    goLogin(); return false;
                }
                if (data.code == 200) {
                    layer.msg('提交成功', { time: 1500 }, function () { window.location.href = '{{:url("/admin/product")}}' });
                } else if (data.code == 400) {
                    layer.msg(data.message); return false;
                } else {
                    layer.msg('操作失败'); return false;
                }
            });
        });
    },
    invalidHandler: function (form, validator) {
        goTop();
    }
});

$(document).ready(function(){
    // if({{$product.model_id}} > 0) {
    //     $("select[name=product_model_id]").val({{$product.model_id}});
    //     $("select[name=product_model_id]").change();
    // }
});    
</script>
</body>
</html>